﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameConstructor;

namespace TetrisShape
{
    public class Shape : Block
    {
        int lineCount = 0;
        private string shapeType = null;
        public string ShapeType
        {
            get { return shapeType; }
            protected set { shapeType = value; }
        }

        private List<Block> block = new List<Block>();
        public List<Block> ReturnBlock { get { return block; } }

        private List<Shape> MynewShape = new List<Shape>();
        public List<Shape> ReturnShape { get { return MynewShape; } }

        Block Firstblock;
        Block Secondblock;
        Block Thirdblock;
        Block Fourthblock;

        public void AddShape(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4, ConsoleColor color)
        {
            Firstblock = new Block(x1, y1);
            block.Add(Firstblock);
            Secondblock = new Block(x2, y2);
            block.Add(Secondblock);
            Thirdblock = new Block(x3, y3);
            block.Add(Thirdblock);
            Fourthblock = new Block(x4, y4);
            block.Add(Fourthblock);
        }

        public Shape CreateRandomShape(Frame fr, Shape sh)
        {

            Random rnd = new Random();
            int i = rnd.Next(7);
            switch (0)
            {
                case 0: sh.AddShape(fr.StartX + 6, fr.StartY + 4, fr.StartX + 6, fr.StartY + 3, fr.StartX + 6, fr.StartY + 2, fr.StartX + 6, fr.StartY + 1, ConsoleColor.Red); ShapeType = "Line"; break;
                case 1: sh.AddShape(fr.StartX + 6, fr.StartY + 2, fr.StartX + 6, fr.StartY + 1, fr.StartX + 5, fr.StartY + 2, fr.StartX + 5, fr.StartY + 1, ConsoleColor.Blue); ShapeType = "Block"; break;
                case 2: sh.AddShape(fr.StartX + 6, fr.StartY + 2, fr.StartX + 5, fr.StartY + 1, fr.StartX + 6, fr.StartY + 1, fr.StartX + 7, fr.StartY + 1, ConsoleColor.Yellow); ShapeType = "T"; break;
                case 3: sh.AddShape(fr.StartX + 6, fr.StartY + 3, fr.StartX + 6, fr.StartY + 2, fr.StartX + 5, fr.StartY + 2, fr.StartX + 5, fr.StartY + 1, ConsoleColor.Green); ShapeType = "ZigZag"; break;
                case 4: sh.AddShape(fr.StartX + 5, fr.StartY + 3, fr.StartX + 5, fr.StartY + 2, fr.StartX + 6, fr.StartY + 2, fr.StartX + 6, fr.StartY + 1, ConsoleColor.Cyan); ShapeType = "ZigZagReverse"; break;
                case 5: sh.AddShape(fr.StartX + 5, fr.StartY + 3, fr.StartX + 5, fr.StartY + 2, fr.StartX + 5, fr.StartY + 1, fr.StartX + 6, fr.StartY + 1, ConsoleColor.DarkBlue); ShapeType = "G"; break;
                case 6: sh.AddShape(fr.StartX + 6, fr.StartY + 3, fr.StartX + 6, fr.StartY + 2, fr.StartX + 6, fr.StartY + 1, fr.StartX + 5, fr.StartY + 1, ConsoleColor.DarkYellow); ShapeType = "GReverse"; break;
            }
            MynewShape.Add(sh);
            return sh;
        }

        public void SetColor()
        {
            if (shapeType == "Line")
                Console.ForegroundColor = ConsoleColor.Red;
            else if (shapeType == "Block")
                Console.ForegroundColor = ConsoleColor.Blue;
            else if (shapeType == "T")
                Console.ForegroundColor = ConsoleColor.Yellow;
            else if (shapeType == "ZigZag")
                Console.ForegroundColor = ConsoleColor.Green;
            else if (shapeType == "ZigZagReverse")
                Console.ForegroundColor = ConsoleColor.Cyan;
            else if (shapeType == "G")
                Console.ForegroundColor = ConsoleColor.DarkBlue;
            else if (shapeType == "GReverse")
                Console.ForegroundColor = ConsoleColor.DarkYellow;
        }

        public void SetFieldColor()
        {
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
        }

        public void RotateLine()
        {
            if (lineCount == 0)
            {
                Firstblock.SetX(Firstblock.X - 2);
                Firstblock.SetY(Firstblock.Y - 2);
                Secondblock.SetX(Secondblock.X - 1);
                Secondblock.SetY(Secondblock.Y - 1);
                Thirdblock.SetX(Thirdblock.X);
                Thirdblock.SetY(Thirdblock.Y);
                Fourthblock.SetX(Fourthblock.X + 1);
                Fourthblock.SetY(Fourthblock.Y + 1);
                lineCount = 1;
            }
            else
            {
                Firstblock.SetX(Firstblock.X + 2);
                Firstblock.SetY(Firstblock.Y + 2);
                Secondblock.SetX(Secondblock.X + 1);
                Secondblock.SetY(Secondblock.Y + 1);
                Thirdblock.SetX(Thirdblock.X);
                Thirdblock.SetY(Thirdblock.Y);
                Fourthblock.SetX(Fourthblock.X - 1);
                Fourthblock.SetY(Fourthblock.Y - 1);
                lineCount = 0;
            }
        }
    }
}